package com.googlecode.wmlynar.javadoctc.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;

public class MyFileUtil {
    
    public static synchronized void writeBytes(String dir, String name, byte[] bytes) {
        
        new File(dir).mkdirs();
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(dir + "/" + name);
            fos.write(bytes);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static synchronized void writeString(String dir, String name, String text) {
        new File(dir).mkdirs();
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(dir + "/" + name);
              final PrintStream ps = new PrintStream(fos);
              ps.print(text);
              ps.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static synchronized void appendString(String dir, String name, String text) {
        new File(dir).mkdirs();
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(dir + "/" + name,true);
              final PrintStream ps = new PrintStream(fos);
              ps.print(text);
              ps.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
